package com.dream.technology.service.impl;

import com.dream.technology.components.riskControl.tianji.RcConstan;
import com.dream.technology.db.dao.RcRuleCollectionItemMapper;
import com.dream.technology.db.entity.RcRuleCollectionItem;
import com.dream.technology.db.entity.RcRuleCollectionItemQuery;
import com.dream.technology.service.RcRuleCollectionItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("rcRuleCollectionItemService")
public class RcRuleCollectionItemServiceImpl implements RcRuleCollectionItemService {

    @Autowired
    RcRuleCollectionItemMapper rcRuleCollectionItemMapper;

    @Override
    public int countByExample(RcRuleCollectionItemQuery example) {
        return rcRuleCollectionItemMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(RcRuleCollectionItemQuery example) {
        return rcRuleCollectionItemMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return rcRuleCollectionItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(RcRuleCollectionItem record) {
        return rcRuleCollectionItemMapper.insert(record);
    }

    @Override
    public int insertSelective(RcRuleCollectionItem record) {
        return rcRuleCollectionItemMapper.insertSelective(record);
    }

    @Override
    public List<RcRuleCollectionItem> selectByExample(RcRuleCollectionItemQuery example) {
        return rcRuleCollectionItemMapper.selectByExample(example);
    }

    @Override
    public RcRuleCollectionItem selectByPrimaryKey(Long id) {
        return rcRuleCollectionItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(RcRuleCollectionItem record, RcRuleCollectionItemQuery example) {
        return rcRuleCollectionItemMapper.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByExample(RcRuleCollectionItem record, RcRuleCollectionItemQuery example) {
        return rcRuleCollectionItemMapper.updateByExample(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(RcRuleCollectionItem record) {
        return rcRuleCollectionItemMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(RcRuleCollectionItem record) {
        return rcRuleCollectionItemMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<RcRuleCollectionItem> selectByCollectionId(Long id) {
        RcRuleCollectionItemQuery query = new RcRuleCollectionItemQuery();
        RcRuleCollectionItemQuery.Criteria criteria = query.createCriteria();
        criteria.andCollectionIdEqualTo(id);
        List<RcRuleCollectionItem> rcRuleCollectionItems = rcRuleCollectionItemMapper.selectByExample(query);

        return rcRuleCollectionItems;
    }

    /**
     * copy 指定collectionId的规则配置
     *
     * @param collectionId
     * @param newCollectionId
     * @return
     */
    @Override
    public String copy(Long collectionId, Long newCollectionId) {
        List<RcRuleCollectionItem> rcRuleCollectionItems = selectByCollectionId(collectionId);
        ArrayList<RcRuleCollectionItem> listTtem = new ArrayList<>();
        rcRuleCollectionItems.forEach(item ->{
            item.setId(null);
            item.setCollectionId(newCollectionId);
            listTtem.add(item);
        });
        insertList(listTtem);
        return RcConstan.SUCCESS;
    }

    /**
     * 批量插入
     * @param record
     * @return
     */
    @Override
    public int insertList(List<RcRuleCollectionItem> record) {
        return rcRuleCollectionItemMapper.insertList(record);
    }







}
